import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs/Observable';

// import { User } from '../models/index';
// import { Header } from 'primeng/primeng';

@Injectable()
export class DetailsService {

    //  url1 = "http://203.81.246.122:8080/api/security/login";


    constructor(private http: HttpClient, @Inject('API_URL') private url: string) { }

    //根据数量请求最新的数据
    getCountHistory(typeId, deviceId, count): Observable<any> {
        const url = `${this.url}${typeId}/essential/latest/target/${deviceId}/${count}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');

        return this.http
            .get(url, { headers: headers })
    }
    //根据时间请求历史数据 缺少length
    getTimeHistory(typeId, deviceId, start, end,length): Observable<any> {
        const url = `${this.url}${typeId}/essential/target/${deviceId}/${start}/${end}?offset=0&length=${length}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');

        return this.http
            .get(url, { headers: headers })
    }
    //
    getStatistics(typeId, deviceId, dataQuota, start, end) {
        const url = `${this.url}${typeId}/statistic/target/${deviceId}/${dataQuota}/${start}/${end}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');
        return this.http
            .get(url, { headers: headers })
    }
    //在某一时间段按日统计数据
    getDayStatistics(typeId, deviceId, dataQuota, start, end) {
        const url = `${this.url}${typeId}/statistic/target/daily/${deviceId}/${dataQuota}/${start}/${end}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');
        return this.http
            .get(url, { headers: headers })
    }
    getWeekStatistics(typeId, deviceId, dataQuota, start, end) {
        const url = `${this.url}${typeId}/statistic/target/weekly/${deviceId}/${dataQuota}/${start}/${end}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');
        return this.http
            .get(url, { headers: headers })
    }
    getMonthStatistics(typeId, deviceId, dataQuota, start, end) {
        const url = `${this.url}${typeId}/statistic/target/monthly/${deviceId}/${dataQuota}/${start}/${end}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');
        return this.http
            .get(url, { headers: headers })
    }
    getSeasonStatistics(typeId, deviceId, dataQuota, start, end) {
        const url = `${this.url}${typeId}/statistic/target/quarterly/${deviceId}/${dataQuota}/${start}/${end}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');
        return this.http
            .get(url, { headers: headers })
    }

    //获取length
    count(typeId, targetId, start, end) {
        const url = `${this.url}${typeId}/essential/count/target/${targetId}/${start}/${end}`;
        const headers = new HttpHeaders()
            .set('Accept', 'application/json;charset=UTF-8');
        return this.http
            .get(url, { headers: headers })
    }

    getname(targetType){
        const url = `${this.url}settings/attribute/data/${targetType}`;
        const headers = new HttpHeaders()
          .set('Accept', 'application/json;charset=UTF-8');
        return this.http.get(url, { headers: headers });
      }


}
